package cn.sylinx.common.ext.web;

import java.io.Serializable;

public class Resp implements Serializable {

	// 是否调用成功
	private boolean success = true;

	// 返回码
	private int code = 500;

	// 返回数据
	private Object data;

	// 错误时的消息
	private String error;

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public static Resp error(String error) {
		return error(500, error);
	}

	public static Resp error(int code, String error) {
		return error(code, null, error);
	}

	public static Resp error(Object data, String error) {
		return error(500, data, error);
	}

	public static Resp error(int code, Object data, String error) {
		Resp pp = new Resp();
		pp.setSuccess(false);
		pp.setError(error);
		pp.setData(data);
		pp.setCode(code);
		return pp;
	}

	public static Resp success() {
		return success(null);
	}

	public static Resp success(Object data) {
		return success(200, data);
	}

	public static Resp success(int code, Object data) {
		Resp pp = new Resp();
		pp.setSuccess(true);
		pp.setData(data);
		pp.setCode(code);
		return pp;
	}
}
